package com.ruoyi.comment.service.impl;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.comment.mapper.CommentMapper;
import com.ruoyi.comment.domain.Comment;
import com.ruoyi.comment.service.ICommentService;

/**
 * 评价记录Service业务层处理
 *
 * @author ch
 * @date 2021-11-24
 */
@Service
public class CommentServiceImpl implements ICommentService
{
    @Autowired
    private CommentMapper commentMapper;

    /**
     * 查询评价记录
     *
     * @param id 评价记录主键
     * @return 评价记录
     */
    @Override
    public Comment selectCommentById(Long id)
    {
        return commentMapper.selectCommentById(id);
    }

    /**
     * 查询评价记录列表
     *
     * @param comment 评价记录
     * @return 评价记录
     */
    @Override
    public List<Comment> selectCommentList(Comment comment)
    {
        return commentMapper.selectCommentList(comment);
    }

    /**
     * 新增评价记录
     *
     * @param comment 评价记录
     * @return 结果
     */
    @Override
    public int insertComment(Comment comment)
    {
        comment.setCreateTime(DateUtils.getNowDate());
        return commentMapper.insertComment(comment);
    }

    /**
     * 修改评价记录
     *
     * @param comment 评价记录
     * @return 结果
     */
    @Override
    public int updateComment(Comment comment)
    {
        comment.setUpdateTime(DateUtils.getNowDate());
        return commentMapper.updateComment(comment);
    }

    /**
     * 批量删除评价记录
     *
     * @param ids 需要删除的评价记录主键
     * @return 结果
     */
    @Override
    public int deleteCommentByIds(Long[] ids)
    {
        return commentMapper.deleteCommentByIds(ids);
    }


    /**
     * 批量逻辑删除评价记录
     *
     * @param ids 需要删除的评价记录主键
     * @return 结果
     */
    @Override
    public int logicDeleteComment(Long[] ids,String delType,Long delUser)
    {
        return commentMapper.logicDeleteComment(ids,delType,delUser);
    }

    /**
     * 删除评价记录信息
     *
     * @param id 评价记录主键
     * @return 结果
     */
    @Override
    public int deleteCommentById(Long id)
    {
        return commentMapper.deleteCommentById(id);
    }
    @Override
    public JSONObject storeCommentAvg(Long storeId){
        JSONObject result=new JSONObject();
        Map resultMap= commentMapper.storeCommentAvg(storeId);
        result.put("STORELEVEL",((BigDecimal)resultMap.get("storelevel")));
        result.put("EFFECTLEVEL",((BigDecimal)resultMap.get("effectlevel")));
        result.put("ENVIRONMENTLEVEL",((BigDecimal)resultMap.get("environmentlevel")));
        result.put("SERVICELEVEL",((BigDecimal)resultMap.get("servicelevel")));
        return result;
    }
}
